<style scoped>
.warehouseTakeStock {
  margin-right: 15px;
  padding: 0 15px;
  background-color: white;
  height: 94.5vh;
  position: relative;
}
.wq-top {
  padding: 15px 0;
  display: flex;
  border-bottom: 2px solid #f4f4f4;
}
.wq-top p:first-child {
  margin: 3px 6px 0 0;
}
.wq-top p:not(:first-child) {
  margin: 3px 6px 0 12px;
}
.wq-content {
  display: flex;
}
.content-left {
  width: 35%;
  /* border:1px solid springgreen; */
  border-right: 2px solid #f4f4f4;
}
.content-left div {
  padding: 10px 15px 0 15px;
}
.content-right {
  width: 65%;
}
.content-right > div:first-child {
  display: flex;
  justify-content: space-between;
  padding: 15px 15px 0 15px;
}
.content-right > div {
  padding: 15px 0 15px 15px;
}
.content-right > div > div {
  display: flex;
}
.content-right > div > div > p {
  margin: 3px 12px 0 0;
}
.footView span {
  float: left;
  margin-right: 48px;
  line-height: 6vh;
  font-size: 14px;
}
.footView span i {
  margin-right: 5px;
}
.dr {
  margin-left: 10px;
}
</style>

<style>
.warehouseTakeStock .wq-top .el-input__inner {
  height: 30px;
}
.warehouseTakeStock .wq-content .content-right .el-checkbox.is-bordered {
  padding: 5px 10px 0 10px;
  height: 30px;
}
.warehouseTakeStock .wq-top .el-input__icon {
  line-height: 31px;
}
.warehouseTakeStock .wq-content .content-left .el-input__inner {
  height: 30px;
}
.warehouseTakeStock .wq-content .content-left .el-input__icon {
  height: 116%;
}
</style>

<template>
  <div class="warehouseTakeStock">
    <div class="wq-top">
      <p>盘点日期</p>
      <el-date-picker v-model="checkDate" type="date" placeholder="选择日期">
      </el-date-picker>
      <p>仓库编号</p>
      <el-input
        v-model="warehouseNo"
        @change="Changeinp"
        style="width: 60px; margin-right: 10px"
      ></el-input>
      <el-select
        style="width: 100px"
        v-model="warehouseName"
        @change="
          (e) => {
            this.warehouseNo = e
          }
        "
      >
        <el-option
          v-for="item in warehouseList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>

    <div class="wq-content">
      <div class="content-left">
        <div>
          <el-select
            v-model="reader"
            style="width: 120px; margin-right: 10px"
            @change="readerChange"
          >
            <el-option
              v-for="item in readerList"
              :key="item.equipmentCabinetNo"
              :label="item.equipmentCabinetNo"
              :value="item.equipmentCabinetNo"
            >
            </el-option>
          </el-select>
          <el-button @click="readRfid">读卡</el-button>
          <el-button @click="reduace">减标</el-button>
          <el-button @click="empty">清空</el-button>
        </div>
        <el-table
          id="outTable"
          height="700px"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '26px' }"
          :data="tabData"
          highlight-current-row
          ref="tabData"
          style="width: 100%"
        >
          <el-table-column type="selection" width="50"> </el-table-column>
          <el-table-column prop="showCode" label="RFID"> </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="kindsNumber"
            label="款号"
          >
          </el-table-column>
          <el-table-column prop="sellingPrice" label="售价"> </el-table-column>
          <el-table-column prop="rd" label="入单"> </el-table-column>
        </el-table>
      </div>

      <div class="content-right">
        <div>
          <div>
            <el-button @click="nBd" type="primary" icon="el-icon-plus"
              >新建</el-button
            >
            <el-button @click="confirm" icon="el-icon-circle-check"
              >确认</el-button
            >
            <el-button
              @click="
                () => {
                  this.exp('仓库盘点')
                  this.exp1('仓库盘点')
                }
              "
              icon="el-icon-upload2"
              >导出</el-button
            >
            <!-- <el-button icon="el-icon-download">导入</el-button> -->
            <div class="dr">
              <i class="el-icon-download"></i>
              导入
              <input
                ref="upload"
                accept=".xls, .xlsx"
                class="outputlist_upload"
                type="file"
              />
            </div>
            <el-button v-print="'#outTable1'" icon="el-icon-printer"
              >列印</el-button
            >
            <el-button @click="Delete" icon="el-icon-delete">删除</el-button>
          </div>
          <div>
            <p>数量：{{ howMany }}</p>
            <p>盘点序号：{{ sequence }}</p>
            <el-checkbox v-model="checked" border>二维</el-checkbox>
          </div>
        </div>
        <el-table
          id="outTable1"
          height="715px"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '26px' }"
          :data="tab1Data"
          highlight-current-row
          :row-class-name="rowClassName"
          ref="tab1Data"
          @row-click="rowClick1"
          style="width: 100%"
        >
          <el-table-column type="selection" width="50"> </el-table-column>
          <template v-for="i in Tab">
            <el-table-column
              show-overflow-tooltip
              :prop="i.prop"
              :label="i.label"
              :width="i.width"
              :key="i.prop + Math.random()"
            >
            </el-table-column>
          </template>
        </el-table>
      </div>
    </div>

    <new-build
      :style="{ display: shownbuild }"
      @closeNew_build="
        () => {
          this.shownbuild = 'none'
        }
      "
      @saveNew_build="saveNew_build"
      @keepGoing="keepGoing"
      @inpNumChange="
        () => {
          this.inpList = this.getInput()
        }
      "
      :warehouse="this.warehouseNo"
    >
    </new-build>

    <foot-view class="footView">
      <div slot="text">
        <el-popover
          placement="top-start"
          width="120"
          max-height="100px"
          trigger="click"
        >
          <el-checkbox-group v-model="selectHeaderList">
            <el-checkbox
              v-for="i in headerList"
              :label="i.value"
              :key="i.value"
              style="margin-bottom: 7px"
            ></el-checkbox>
          </el-checkbox-group>
          <i slot="reference" class="el-icon-date"> 表头配置</i>
        </el-popover>
        <span>数据库：{{ jxQuarter }}</span>
      </div>
    </foot-view>
  </div>
</template>

<script>
import XLSX from 'xlsx'
import FileSaver from 'file-saver'
import newBuild from './childComp/new_build'
import footView from '../../../components/FootView'
import today from '../../../components/mixins/today'
import outex from '../../../components/mixins/outexp'
import { getWarehouse } from '../../../network/warehouse'
import enterUp from '../../../components/mixins/enterUp'
import exportMethods from '../../../components/mixins/exportMethods'
import {
  InventoryNewBuild,
  confirmInventory,
  Empty,
  Reduace,
  DeleteOrder
} from '../../../network/manufacturer'
import {
  UHFConnection,
  connectStatus,
  close,
  sendOrder,
  orderList,
  getUhfTest
} from '../../../network/rfid'
// import { delete } from 'vue/types/umd'
import { internetProtocol } from '../../../config/ip'
export default {
  name: 'warehouse_take_stock_i',
  mixins: [today, enterUp, exportMethods, outex],
  components: {
    footView,
    newBuild
  },
  created() {
    let jxQuarterVal = document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))
    this.jxQuarter = jxQuarterVal ? jxQuarterVal[1] : null
    
    this.Tab = this.tabData1
    this.inpList = this.getInput() //input enter移动
    this.checkDate = this.getNowTime()
    getUhfTest().then((res) => {
      this.readerList = res.data.data
      console.log(res.data, 'getUhfTest')
      if (res.data.code == 200) {
        for (let z of res.data.data) {
          this.ip = z.ip
          this.port = z.port
          this.command = z.testHead + z.testBody
        }
        console.log(this.ip, Number(this.port), this.command)
      }
    })
    //仓库编号
    getWarehouse().then((res) => {
      res.data.data.forEach((e) => {
        this.warehouseList.push({ value: e.no, label: e.name })
        if (e.isMainWarehouse) {
          this.warehouseNo = e.no
          this.warehouseName = e.name
        }
      })
    })
  },
  data() {
    return {
      oneList: [],
      twoList: [],
      howMany: 0,
      //讀卡發送時間
      enteringTime: '',
      // 当前读卡的原始数据
      originalData: {},
      tabData: [],
      rfidList1: [],
      switchList: [],
      efficacious: [],
      loading: {},
      reader: '',
      readerList: [],
      showTab: false,
      jxQuarter: null,
      // jxQuarter: document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))[1],
      ip: '',
      port: '',
      command: '',
      inpList: [],
      RfidList: [],
      sid: '',
      sequence: '',
      confirmData: [],
      shownbuild: 'none',
      checkDate: [],
      tabData: [],
      tab1Data: [],
      checked: '',
      warehouseList: [],
      warehouseNo: '',
      warehouseName: '',
      details: [],
      // details1:{},
      headerList: [],
      selectHeaderList: [],
      houseNo: '',
      ta: [],
      ti: [],
      tabData1: [
        {
          prop: 'kindsNumber',
          label: '款号',
          width: '140'
        },
        {
          prop: 'colorName',
          label: '颜色',
          width: '80'
        },
        {
          prop: 'size',
          label: '尺码编号'
        },
        {
          prop: 'stockingNumber',
          label: '数量'
        },
        {
          prop: 'onePrice',
          label: '单价'
        },
        {
          prop: 'stockingMoney',
          label: '金额'
        },
        {
          prop: 'sellingPrice',
          label: '售价'
        },
        {
          prop: 'commodityName',
          label: '品名'
        },
        {
          prop: 'brandName',
          label: '品牌'
        },
        {
          prop: 'enteringTime',
          label: '录入日期',
          width: '110px'
        }
      ],
      Tab: [],
      tabData2: [
        {
          prop: 'typeNumber',
          label: '款号',
          width: '140'
        },
        {
          prop: 'colorName',
          label: '颜色',
          width: '80'
        },
        {
          prop: 'sizeNo',
          label: '尺码编号',
          with: '70'
        },
        {
          prop: 'c05',
          label: '05-XS',
          width: '70'
        },
        {
          prop: 'c07',
          label: '07-S',
          width: '70'
        },
        {
          prop: 'c09',
          label: '09-M',
          width: '70'
        },
        {
          prop: 'c11',
          label: '11-L',
          width: '70'
        },
        {
          prop: 'c13',
          label: '13-XL',
          width: '70'
        },
        {
          prop: 'c15',
          label: '15-2L',
          width: '70'
        },
        {
          prop: 'c17',
          label: '17-3L',
          width: '70'
        },
        {
          prop: 'c19',
          label: '19-4L',
          width: '80'
        },
        {
          prop: 'c21',
          label: '21-5L',
          width: '80'
        },
        {
          prop: 'c23',
          label: '23-6L'
        },
        {
          prop: 'f',
          label: 'D',
          width: '80'
        },
        {
          prop: 'total',
          label: '小计',
          width: ''
        },
        {
          prop: 'sellingPrice',
          label: '售价',
          width: ''
        },
        {
          prop: 'money',
          label: '售价金额',
          width: ''
        },
        {
          prop: 'brandName',
          label: '品牌',
          width: '100'
        },
        {
          prop: 'quarterName',
          label: '季度',
          width: ''
        }
      ]
    }
  },
  methods: {
    readerChange() {},

    readRfid() {
      if (!this.reader) {
        this.$message({
          offset: 400,
          type: 'warning',
          message: '请选择读卡机'
        })
      }
      var sid = Math.random().toString(36).substring(2, 7)
      this.sid = sid
      var ws = new WebSocket(`wss://${internetProtocol}/webSocket/` + sid)
      ws.onopen = (e) => {
        // console.log(e)
        UHFConnection({
          host: this.ip,
          port: Number(this.port),
          socketId: sid
        }).then((res) => {})
        setTimeout(() => {
          connectStatus({ socketId: sid }).then((res) => {
            console.log(res.data)
            if (res.data.code == 200) {
              this.tabData = []
              if (!this.sequence) {
                this.rfidList1 = []
              }
              this.switchList = []
              this.efficacious = []
              this.$message.success({ message: '读卡器连接成功，开始读卡' })
              sendOrder({ command: this.command, connectId: this.sid }).then(
                (res) => {
                  console.log(res.data)
                }
              )
              this.loading = this.$loading({
                lock: true,
                text: '读卡中...',
                spinner: 'el-icon-loading',
                background: 'rgba(255, 255, 255, 0)'
              })
            } else if (res.data.code == 201) {
              this.$message.error({ message: '读卡器连接失败' })
            }
          })
        }, 1500)
      }
      ws.onmessage = (event) => {
        // console.log(event)       webSocket 发送信息
        if (event.data == '连接成功') return
        this.RfidList = JSON.parse(event.data)
        // console.log(this.RfidList) webSocket 发送信息
        if (this.RfidList.endCommand) {
          console.log(this.RfidList.endCommand)
          this.$message.success({ message: '读卡完成' })
          this.loading.close()
          ws.onclose()
          this.rfidAdd()
        }
        if (this.RfidList.isConnectError) {
          this.$message.error(
            `请检查路由器外网IP是否与此IP一致 ：${this.RfidList.connectTimeOutIp}`
          )
          this.loading.close()
          ws.close()
        }
        if (this.RfidList.validShowCode) {
          if (this.rfidList1.length) {
            let exist = 0
            for (const i of this.rfidList1) {
              if (i.showCode == this.RfidList.validShowCode) {
                exist = 1
                break
              }
            }
            if (!exist) {
              this.rfidList1.unshift({ showCode: this.RfidList.validShowCode })
              this.efficacious.push({ showCode: this.RfidList.validShowCode })
            }
          } else {
            this.rfidList1.unshift({ showCode: this.RfidList.validShowCode })
            this.efficacious.push({ showCode: this.RfidList.validShowCode })
          }
          this.tabData.unshift({
            showCode: this.RfidList.validShowCode,
            index: this.tabData.length + 1
          })
        }

        if (this.RfidList.otherErrorRFID) {
          if (this.tabData.length) {
            let exist = 0
            for (const i of this.tabData) {
              if (i.showCode.indexOf(this.RfidList.otherErrorRFID) != -1) {
                exist = 1
                break
              }
            }
            if (!exist) {
              this.tabData.unshift({
                showCode: this.RfidList.otherErrorRFID + '其他错误',
                index: this.tabData.length + 1
              })
            }
          } else {
            this.tabData.unshift({
              showCode: this.RfidList.otherErrorRFID + '其他错误',
              index: this.tabData.length + 1
            })
          }
        }

        if (this.RfidList.antennaErrorRFID) {
          if (this.tabData.length) {
            let exist = 0
            for (const i of this.tabData) {
              if (i.showCode.indexOf(this.RfidList.antennaErrorRFID) != -1) {
                exist = 1
                break
              }
            }
            if (!exist) {
              this.tabData.unshift({
                showCode:
                  this.RfidList.antennaErrorRFID +
                  '天线错误' +
                  this.RfidList.antennaErrorIndex,
                index: this.tabData.length + 1
              })
            }
          } else {
            this.tabData.unshift({
              showCode:
                this.RfidList.antennaErrorRFID +
                '天线错误' +
                this.RfidList.antennaErrorIndex,
              index: this.tabData.length + 1
            })
          }
        }
      }
      ws.onclose = () => {
        console.log('连接关闭')
        // close({socketId:this.sid}).then(res=>{
        //   console.log(res.data)
        // })
      }
      ws.onerror = (event) => {
        console.log(event)
      }
    },
    rfidAdd() {
      var showCodeList = []
      // for(let a1 in this.tabData){
      //   showCodeList.push({showCode:this.tabData[a1]})
      // }
      this.tabData.forEach((e) => {
        showCodeList.push(e.showCode)
      })
      let obj = {
        dataSource: 0,
        warehouseNo: this.warehouseNo,
        checkDate: this.checkDate,
        sequence: this.sequence,
        showCodeList,
        enteringTime: this.enteringTime
      }
      console.log(obj)
      InventoryNewBuild(JSON.stringify(obj)).then((res) => {
        console.log(res)
        if (res.data.code == 200) {
          this.tabData = []
          res.data.data.insertBatchList.forEach((e) => {
            this.tab1Data.push(e)
            this.sequence = e.sequence
            this.enteringTime = e.enteringTime
          })
          for (let d in res.data.data.rfidList) {
            res.data.data.rfidList[d]['rd'] = 0
          }
          this.tabData = res.data.data.rfidList
          this.howMany = res.data.data.rfidList.length
          if (res.data.data.errorRfidList != undefined) {
            // this.exportRaw(String(res.data.data.errorRfidList),'库存不足Rfid.txt')
          }
        }
      })
    },

    rowClassName({ row, rowIndex }) {
      row.xh = rowIndex + 1
    },
    //删除
    Delete() {
      if (this.sequence == '') {
        return
      }

      this.ti = this.$refs.tab1Data.selection
      console.log(this.ti)

      if (this.ti == '' && this.sequence != '') {
        this.$confirm('是否删除此盘点序号的所有货号数据 是否确认？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          DeleteOrder(JSON.stringify({ sequence: this.sequence })).then(
            (res) => {
              console.log(res.data)
              if (res.data.code == 200) {
                this.$message({
                  type: 'success',
                  offset: 400,
                  message: '删除成功'
                })
                this.sequence = ''
                this.tab1Data = []
                this.howMany = ''
              } else {
                this.$message.error({
                  offset: 400,
                  message: '删除失败'
                })
              }
            }
          )
        })
      } else if (this.ti != '' && this.sequence != '') {
        var as = []
        var ad = []
        var af = {}
        for (let b in this.ti) {
          console.log(this.ti[b])
          // b.kindsNumber
          as.push(this.ti[b].kindsNumber)
          ad.push(this.ti[b].stockingNumber)
          for (let s in as) {
            for (let d in ad) {
              if (s == d) {
                af[as[s]] = ad[s]
              }
            }
          }
        }
        console.log(af)
        this.$confirm('是否删除选中数据 是否确认？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var ol = { sequence: this.sequence, kindsNumberMap: af }
          console.log(JSON.stringify(ol))
          DeleteOrder(JSON.stringify(ol)).then((res) => {
            console.log(res.data)
            if (res.data.code == 200) {
              this.$message({
                type: 'success',
                offset: 400,
                message: '删除成功'
              })
              this.sequence = ''
              this.howMany = ''
              this.ti.forEach((item, index) => {
                this.tab1Data.forEach((itemI, indexI) => {
                  if (item === itemI) {
                    this.tab1Data.splice(indexI, 1)
                  }
                })
              }) //刪除列表選中數據
            } else {
              this.$message.error({
                offset: 400,
                message: '删除失败'
              })
            }
          })
        })
      }
    },
    nBd() {
      if (this.sequence) {
        this.$confirm('将创建新的盘点序号 是否确认？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.sequence = ''
            this.tabData = []
            this.tab1Data = []
            this.howMany = 0
            this.shownbuild = 'block'
          })
          .catch(() => {})
      } else {
        this.shownbuild = 'block'
      }
    },
    //减标
    reduace() {
      if (this.sequence == '') {
        return
      }
      this.ta = this.$refs.tabData.selection
      console.log(this.ta)
      console.log(this.tabData)
      if (this.ta.length == this.tabData.length) {
        this.empty()
      }
      if (this.ta == '') {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '请选择减标数据'
        })
        return
      }
      var showCodeList = []
      this.ta.forEach((e) => {
        showCodeList.push(e.showCode)
      })
      var ol1 = { showCodeList, sequence: this.sequence }
      console.log(JSON.stringify(ol1))
      this.$confirm('是否删除选中数据 是否确认？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Reduace(JSON.stringify(ol1)).then((res) => {
          console.log(res.data)
          if (res.data.code == 200) {
            this.$message({
              type: 'success',
              offset: 400,
              message: '减标成功'
            })
            this.ta.forEach((item, index) => {
              this.tabData.forEach((itemI, indexI) => {
                if (item === itemI) {
                  this.tabData.splice(indexI, 1)
                }
              })
            })
            this.ta.forEach((item, index) => {
              this.tab1Data.forEach((item1, index1) => {
                if (
                  item.kindsNumber == item1.kindsNumber &&
                  item1.stockingNumber == 1
                ) {
                  this.tab1Data.splice(index1, 1)
                }
                if (
                  item.kindsNumber == item1.kindsNumber &&
                  item1.stockingNumber > 1
                ) {
                  item1.stockingNumber -= 1
                }
              })
            }) //删除与左表关联的右表数据
          } else {
            this.$message.error({
              message: '减标失败'
            })
          }
        })
      })
    },
    //清空
    empty() {
      this.$confirm('是否清空此盘点序号的RFID数据 是否确认？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Empty({ sequence: this.sequence }).then((res) => {
          console.log(res.data)
          if (res.data.code == 200) {
            this.$message({
              type: 'success',
              offset: 400,
              message: '清空成功'
            })
            this.tabData.forEach((item, index) => {
              this.tab1Data.forEach((item1, index1) => {
                if (item.kindsNumber === item1.kindsNumber) {
                  this.tab1Data.splice(index1, 1)
                }
              })
            })
            this.tabData = []
          } else {
            this.$message.error({
              offset: 400,
              message: '清空失败'
            })
          }
        })
        // .catch(()=>{
        //   this.$message({
        //       type: 'info',
        //       offset:400,
        //       message: '已取消清空'
        //     });
        // })
      })
    },
    rowClick1(e) {
      // this.details1 = e
    },

    confirm() {
      if (this.tab1Data == '' && this.tabData == '') {
        return
      }
      for (var m of this.tab1Data) {
        var sequence = m.sequence
      }
      for (let n of this.tabData) {
        var sequence1 = n.sequence
      }
      var obj = {}
      if (sequence == '') {
        obj = { sequence: sequence1 }
      } else if (sequence1 == '') {
        obj = { sequence: sequence }
      }
      this.$confirm(
        '确认后不可对此单进行改单,删单和补单操作 是否确认？',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        confirmInventory({ sequence: sequence }).then((res) => {
          console.log(res.data)
          if (res.data.code == 200) {
            for (let l of this.tab1Data) {
              if (sequence == l.sequence) {
                l.affirm = 1
              }
            }

            for (let k of this.tabData) {
              if (sequence == k.sequence) {
                k.affirm = 1
              }
            }
            this.$message({
              type: 'success',
              offset: 400,
              message: '确认成功!'
            })
          } else {
            this.$message.error({
              offset: 400,
              message: '确认失败'
            })
          }
        })
      })
    },

    // 新建保存
    saveNew_build(data) {
      this.confirmData = [data]
      console.log(data)
      InventoryNewBuild(JSON.stringify(data)).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            offset: 400,
            message: '保存成功!'
          })
          console.log(res.data.data.insertBatchList)
          // var ml = []
          // res.data.data.insertBatchList.forEach(e=>{
          //   this.tab1Data.push(e)
          // })
          // console.log(this.tab1Data)
          this.tab1Data = res.data.data.insertBatchList
          this.oneList = res.data.data.insertBatchList
          this.twoList = res.data.data.twoList

          if (res.data.data.rfidList !== undefined) {
            res.data.data.rfidList.forEach((e) => {
              this.tabData.push(e)
            })
          } else {
          }

          this.howMany = this.tab1Data.reduce((prev, next) => {
            //tab1Data数组里所有money的和
            return prev + next.stockingNumber
          }, 0)

          for (var c of this.tab1Data) {
            this.sequence = c.sequence
            console.log(this.sequence) //序号
            this.houseNo = c.warehouseNo
          }
          if (res.data.data.errorRfidList !== undefined) {
            this.exportRaw(
              String(res.data.data.errorRfidList),
              '库存不足Rfid.txt'
            )
          }
        } else {
          this.$message.error({
            message: '保存失败'
          })
        }
      })
      this.shownbuild = 'none'
    },
    keepGoing(data) {
      InventoryNewBuild(JSON.stringify(data)).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            offset: 400,
            message: '保存成功!'
          })
          console.log(res.data.data.insertBatchList)
          // var ml = []
          res.data.data.insertBatchList.forEach((e) => {
            this.tab1Data.push(e)
          })
          console.log(this.tab1Data)

          if (res.data.data.rfidList !== undefined) {
            res.data.data.rfidList.forEach((e) => {
              this.tabData.push(e)
            })
          } else {
          }

          for (var c of this.tab1Data) {
            this.sequence = c.sequence
            console.log(this.sequence) //序号
            this.houseNo = c.warehouseNo
          }
          if (res.data.data.errorRfidList !== undefined) {
            this.exportRaw(
              String(res.data.data.errorRfidList),
              '库存不足Rfid.txt'
            )
          }
        } else {
          this.$message.error({
            message: '保存失败'
          })
        }
      })
    },

    // 仓库编号失去焦点
    Changeinp() {
      if (this.warehouseNo != '') {
        for (const i of this.warehouseList) {
          if (this.warehouseNo == i.value) {
            this.warehouseName = i.label
            return
          }
        }
        this.$message({
          type: 'error',
          message: '无此仓库编号'
        })
        this.warehouseNo = ''
        this.warehouseName = ''
      } else {
        this.warehouseName = ''
      }
    },
    //导入
    readExcel(e) {
      //表格导入
      var that = this
      const files = e.target.files
      if (files.length <= 0) {
        //如果没有文件名
        return false
      } else if (!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())) {
        this.$Message.error('上传格式不正确，请上传xls或者xlsx格式')
        return false
      }

      const fileReader = new FileReader()
      fileReader.onload = (ev) => {
        try {
          const data = ev.target.result
          const workbook = XLSX.read(data, {
            type: 'binary'
          })
          const wsname = workbook.SheetNames[0] //取第一张表
          const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]) //生成json表格内容
          let kindsNumberMap = {}
          let showCodeList = []
          for (let v of ws) {
            if (v.数据来源 == 1) {
              kindsNumberMap[v.货号] = v.数量
            } else if (v.数据来源 == 0) {
              showCodeList.push(v.ID编号)
            }
          }
          const params = {
            checkDate: ws[0].盘点日期 == undefined ? '' : ws[0].盘点日期,
            dataSource: ws[0].数据来源,
            enteringTime: ws[0].录入时间 == undefined ? '' : ws[0].录入时间,
            kindsNumberMap,
            showCodeList,
            receiptsNumber: ws[0].单据号 == undefined ? '' : ws[0].单据号,
            sequence: ws[0].盘点序号 == undefined ? '' : ws[0].盘点序号,
            warehouseNo: ws[0].仓库编号
          }
          console.log(params)
          InventoryNewBuild(
            JSON.parse(JSON.stringify(params).replace(/^\[|\]$/g, ''))
          ).then((res) => {
            console.log(res.data)
            if (res.data.code == 200) {
              this.$message({
                type: 'success',
                offset: 400,
                message: '导入成功!'
              })
              res.data.data.insertBatchList.forEach((e) => {
                this.tab1Data.push(e)
              })

              if (res.data.data.rfidList) {
                res.data.data.rfidList.forEach((e) => {
                  this.tabData.push(e)
                })
              }

              for (var c of this.tab1Data) {
                this.sequence = c.sequence
                console.log(this.sequence) //序号
                this.houseNo = c.warehouseNo
              }
              if (res.data.data.errorRfidList !== undefined) {
                this.exportRaw(
                  String(res.data.data.errorRfidList),
                  '库存不足Rfid.txt'
                )
              }
              // this._getClient({limit: this.limit,page: this.currentPage})//重新请求页面数据
            } else {
              this.$message.error({
                offset: 400,
                message: '导入数据错误'
              })
            }
          })

          that.outputs = [] //清空接收数据
          //编辑数据
          for (var i = 0; i < ws.length; i++) {
            var sheetData = {
              address: ws[i].addr,
              value: ws[i].value
            }
            that.outputs.push(sheetData)
          }
          this.$refs.upload.value = ''
        } catch (e) {
          return false
        }
      }
      fileReader.readAsBinaryString(files[0])
    }
  },
  mounted() {
    this.$refs.upload.addEventListener('change', (e) => {
      //绑定监听表格导入事件
      this.readExcel(e)
    })
  },
  watch: {
    checked(a, b) {
      if (a) {
        this.Tab = this.tabData2
        this.tab1Data = this.twoList
      } else {
        this.Tab = this.tabData1
        this.tab1Data = this.oneList
      }
    }
  }
  // $router(a,b){
  //   this.inpList = this.getInput()//input enter移动
  // }
}
</script>
